﻿@using Microsoft.Extensions.Options;
@using Project.Constraints.Page
@using Project.Web.Shared.Components
@using System.Diagnostics.CodeAnalysis
@inherits AppComponentBase
<div class="layout-logo @Class">
    @if (!collapse)
    {
        <img class="logo-img" src="/_content/Project.Web.Shared/assets/logo.png" alt="logo">
        <div class="website-name" style="color: rgb(64, 158, 255);">@(Config.CurrentValue.AppShortName ?? "BlazorWeb")</div>
    }
    @if (ShowCollapseButton)
    {
        <span @onclick="ToggleMenu" style="cursor:pointer;">
            <MIcon ClassName="menu-collapse-icon" IconName="@IconName"></MIcon>
        </span>
    }
</div>

@code {
    [Parameter] public EventCallback<bool> OnToggleCollapse { get; set; }
    [Parameter] public bool ShowCollapseButton { get; set; } = true;
    [Parameter] public string? Class { get; set; }
    [Inject, NotNull] public IOptionsMonitor<AppSetting>? Config { get; set; }
    private bool collapse = false;
    private string IconName => collapse ? "fa fa-indent" : "fa fa-outdent";//"svg-expand_menu" : "svg-collapse_menu";

    protected override void OnInitialized()
    {
        collapse = App.Collapsed;
        _ = OnToggleCollapse.InvokeAsync(collapse);
    }

    async Task ToggleMenu()
    {
        collapse = !collapse;
        await OnToggleCollapse.InvokeAsync(collapse);
    }

    public async Task UpdateToggleMenu(bool state)
    {
        collapse = state;
        await OnToggleCollapse.InvokeAsync(collapse);
    }
}


